//
//  BRNavView.m
//  Kexu
//
//  Created by IOS on 2023/7/11.
//

#import "BRNavView.h"

@implementation BRNavView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)leftClick {
    if (self.leftClickBlock) self.leftClickBlock();
}
- (void)rightClick {
    if (self.rightClickBlock) self.rightClickBlock();
}

- (void)br_hiddenLBtn:(BOOL)hidden {
    
    
    self.btnLeft.hidden = hidden;
    __block CGFloat left = hidden ? 28 : 58;
    [self.titleL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.offset(left);
    }];
}


#pragma mark - UI --
- (void)setUI {
    self.backgroundColor = UIColorClear;
    
    
    
    [self addSubview:self.popView];
    [self addSubview:self.topBGView];
    [self addSubview:self.topView];
    self.popView.frame = CGRectMake(0, 0, kScreenWidth - 28, 52);
    self.topBGView.frame = CGRectMake(0, 0, kScreenWidth, kSafeAreaTopHeight);
    self.topView.frame = CGRectMake(0, 0, kScreenWidth, kSafeAreaTopHeight);
    [self.popView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.bottom.offset(0);
        make.height.mas_equalTo(52);
    }];
    [self.topBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(-8);
        make.top.offset(-28);
    }];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.height.mas_equalTo(kSafeAreaTopHeight);
        make.top.offset(0);
    }];
    self.titleL.numberOfLines = 2;
//    self.titleL.textAlignment = NSTextAlignmentCenter;
    [self.topView addSubview:self.titleL];
//    self.titleL.nub
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(58);
        make.right.offset(-58);
        make.bottom.offset(0);
        make.height.mas_equalTo(52);
    }];
    [self.topView layoutIfNeeded];
    [self.topBGView layoutIfNeeded];
    
    self.popView.layer.cornerRadius = 20;
    self.popView.layer.masksToBounds = YES;
    self.topBGView.layer.cornerRadius = 28;
    self.topBGView.layer.masksToBounds = YES;
    
//    [BRToolsView br_corners:20 corners:UIRectCornerBottomLeft | UIRectCornerBottomRight by:self.popView];
//    [BRToolsView br_corners:28 corners:UIRectCornerBottomLeft | UIRectCornerBottomRight by:self.topBGView];
}

- (void)br_setCornerTopBgVie {
    [BRToolsView br_corners:28 corners:UIRectCornerBottomLeft | UIRectCornerBottomRight by:self.topBGView];
}
- (void)br_setCornerPopVie {
    [BRToolsView br_corners:20 corners:UIRectCornerBottomLeft | UIRectCornerBottomRight by:self.popView];
}


- (void)br_addBtnleft:(NSString *)imgStr {
    [self.btnLeft setImage:UIImageMake(imgStr) forState:UIControlStateNormal];
    [self.topView addSubview:self.btnLeft];
    [self.btnLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.bottom.offset(0);
        make.width.height.mas_equalTo(52);
    }];
    [self.btnLeft addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
}

- (void)br_addBtnRight:(NSString *)imgStr {
    
    [self.btnRight setImage:UIImageMake(imgStr) forState:UIControlStateNormal];
    [self.topView addSubview:self.btnRight];
    [self.btnRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-14);
        make.bottom.offset(0);
        make.width.height.mas_equalTo(52);
    }];
    [self.btnRight addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
}


- (UIView *)topView {
    
    if (_topView == nil) {
        _topView = [UIView new];
        _topView.backgroundColor = UIColor.clearColor;
        
    }
    return _topView;
}

- (UIView *)topBGView {
    
    if (_topBGView == nil) {
        _topBGView = [UIView new];
        _topBGView.backgroundColor = UIColor.whiteColor;
        
    }
    return _topBGView;
}

- (UIView *)popView {
    
    if (_popView == nil) {
        _popView = [UIView new];
        _popView.backgroundColor = UIColorMakeWithHex(@"#EEEEF5");
        _popView.hidden = YES;
    }
    return _popView;
}

- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        
        _titleL = [BRToolsView br_label:@"" textColor:UIColor.blackColor font:[UIFont fontB:17]];
    }
    return _titleL;
}

- (QMUIButton *)btnLeft {
    
    if (_btnLeft == nil) {
        _btnLeft = [QMUIButton buttonWithType:UIButtonTypeCustom];
    }
    return _btnLeft;
}
- (QMUIButton *)btnRight {
    
    if (_btnRight == nil) {
        _btnRight = [QMUIButton buttonWithType:UIButtonTypeCustom];
    }
    return _btnRight;
}

@end
